# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Copyright © 2010, RedJack, LLC.
# All rights reserved.
#
# Please see the LICENSE.txt file in this distribution for license
# details.
# ----------------------------------------------------------------------


def set_options(opt):
    opt.tool_options("compiler_cc")
    opt.tool_options("misc")
    opt.tool_options("osx")


def configure(conf):
    conf.check_tool("compiler_cc")
    conf.check_tool("misc")
    conf.check_tool("osx")

    conf.check_cfg(atleast_pkgconfig_version="0.15.0")

    conf.check_cfg(
        package="glib-2.0",
        uselib_store="GLIB",
        args="--cflags --libs",
        mandatory=True
    )

    conf.env.append_value("RELEASE_DEFINES", "NDEBUG")


def build(bld):
    bld(
        features="cc cshlib",
        source = bld.path.ant_glob("libipset/**/*.c"),
        defines = ['G_LOG_DOMAIN=\"ipset\"'],
        includes = ["../include"],
        target = "ipset",
        uselib = "GLIB",
        vnum = "1.1.0",
        export_incdirs = ["../include"],
    )

    import Utils

    bld(
        features="subst",
        source = Utils.subst_vars("${APPNAME}.pc.in", bld.env),
        target = Utils.subst_vars("${APPNAME}.pc", bld.env),
        install_path = "${PREFIX}/lib/pkgconfig",
    )

    bld(
        features="cc cprogram",
        source = bld.path.ant_glob("ipsetbuild/**/*.c"),
        includes = ["../include"],
        target = "ipsetbuild/ipsetbuild",
        uselib = "GLIB",
        uselib_local = "ipset",
    )

    bld(
        features="cc cprogram",
        source = bld.path.ant_glob("ipsetcat/**/*.c"),
        includes = ["../include"],
        target = "ipsetcat/ipsetcat",
        uselib = "GLIB",
        uselib_local = "ipset",
    )

    bld(
        features="cc cprogram",
        source = bld.path.ant_glob("ipsetdot/**/*.c"),
        includes = ["../include"],
        target = "ipsetdot/ipsetdot",
        uselib = "GLIB",
        uselib_local = "ipset",
    )
